package cn.donting.jme.swing;

import java.math.BigDecimal;
import java.text.ParseException;

public class JBigdecimalTextField extends JNumberTextField<BigDecimal> {

    public JBigdecimalTextField() {
        super(new BigDecimal("0"), new BigDecimal("1"));
    }

    @Override
    protected int compareTo(BigDecimal n1, BigDecimal n2) {
        return n1.compareTo(n2);
    }

    @Override
    protected BigDecimal parse(String text) throws NumberFormatException {
        return new BigDecimal(text);
    }

    @Override
    protected BigDecimal format(String text) throws ParseException {
        return new BigDecimal(text);
    }

    @Override
    protected BigDecimal add(BigDecimal value, BigDecimal value2) {
        return value.add(value2);
    }

    public void setValue(float value) {
        super.setValue(new BigDecimal(value+""));
    }

    @Override
    protected BigDecimal subtraction(BigDecimal value, BigDecimal value2) {
        return value.subtract(value2);
    }
}
